<?php

namespace App\Api\Controllers;

use App\Models\Campus;
use App\Models\Major;
use App\Models\University;
use Dingo\Api\Http\Request;
use Dingo\Api\Routing\Helpers;
use Illuminate\Routing\Controller;

class SchoolController extends Controller
{
    use Helpers;


    public function index(){
        $result=University::all();
        return $this->response()->array([
            'result'=>$result,
            'status_code'=>200,
            'message'=>"获取学校信息成功"
        ]);
    }

    /**
     * @param Request $request
     * @return mixed
     * 专业
     */
    public function major(Request $request){
        $university_id=$request->get('q');
        $from=$request->get('from');
        $result=Major::where('university_id',$university_id)->select('id','name as text')->orderBy('name')->get();

        if($from=='client'){
            return $this->response()->array([
                'message'=>'获取专业信息成功',
                'status_code'=>200,
                'result'=>$result
            ]);
        }else{
            return $this->response()->array($result);
        }

    }
    /**
     * 校区
     */
    public  function campus(Request $request){
        $university_id=$request->get('q');
        $from=$request->get('from');
        $result=Campus::where('university_id',$university_id)->select('id','name as text')->get();
        if($from=='client'){
            return $this->response()->array([
                'message'=>'获取校区信息成功',
                'status_code'=>200,
                'result'=>$result
            ]);
        }else{
            return $this->response()->array($result);
        }
    }


}